package com.byxy.action.basicInfo;

import com.byxy.model.BasicInfo;
import com.byxy.service.BasicInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BasicInfoUpdaetServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6664323664034287428L;

	/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		int id = Integer.parseInt(request.getParameter("txtid"));
		String name = request.getParameter("txtname");
		String sex = request.getParameter("txtsex");
		String familyName = request.getParameter("txtfamilyName");
		String placeOfBirth = request.getParameter("txtplaceOfBirth");
		java.util.Date birthday = java.sql.Date.valueOf(request.getParameter("txtbirthday"));
		String education = request.getParameter("txteducation");
		String post = request.getParameter("txtpost");
		java.util.Date workHours = java.sql.Date.valueOf(request.getParameter("txtworkHours"));
		java.util.Date partyHours = java.sql.Date.valueOf(request.getParameter("txtpartyHours"));
		java.util.Date positiveHours = java.sql.Date.valueOf(request.getParameter("txtpositiveHours"));
		boolean status = Boolean.valueOf(request.getParameter("txtstatus"));
		java.util.Date transitHours = java.sql.Date.valueOf(request.getParameter("txttransitHours"));
		String transferredToTheFormerPartyBranch = request.getParameter("txttransferredToTheFormerPartyBranch");
		String domicileLocation = request.getParameter("txtdomicileLocation");
		String idNumber = request.getParameter("txtidNumber");
		String contactNumber = request.getParameter("txtcontactNumber");
		int qqNumber = Integer.parseInt(request.getParameter("txtqqNumber"));
		String wechatNumber = request.getParameter("txtwechatNumber");
		java.util.Date rollOutHours = java.sql.Date.valueOf(request.getParameter("txtrollOutHours"));
		String nameOfPartyBranch = request.getParameter("txtnameOfPartyBranch");
		String sponsor = request.getParameter("txtsponsor");
		String text = request.getParameter("txttext");
		int departmentId = Integer.parseInt(request.getParameter("txtdepartmentId"));
		BasicInfoServiceImpl basicService = new BasicInfoServiceImpl();
		if (basicService.update(new BasicInfo(id, name, sex, familyName, placeOfBirth, birthday,
				education, post, workHours, partyHours,
				positiveHours, status, transitHours,
				transferredToTheFormerPartyBranch, domicileLocation, idNumber, contactNumber, qqNumber,
				wechatNumber, rollOutHours, nameOfPartyBranch, sponsor, text, departmentId)) == -1) {
			response.sendRedirect("Messages/operationError.html");
		} else {
			response.sendRedirect("Messages/basicInfoSuccesstoupdate.html");
		}
	}

}
